package schoolword;

public class MyRunnable implements Runnable{
    public int  book = 1;
    public int BOOK = 100;
    @Override
    public void run() {
        while (book <= BOOK) {
            if (book == 20 && Thread.currentThread().getName().equals("张三")) {
                Thread.currentThread().interrupt();
            }else if (Thread.currentThread().isInterrupted()) {
                return;
            }
            System.out.println(Thread.currentThread().getName()+"发了第" + book++ + "本书");
        }
    }

    public static void main(String[] args) throws InterruptedException {
         MyRunnable runnable = new MyRunnable();
        Thread t1 = new Thread(runnable,"张三");
        Thread t2 = new Thread(runnable,"李四");
        Thread t3 = new Thread(runnable,"王五");

        t1.start();
        t1.join();
        t2.start();
        t3.start();
    }
}
